


//首页加载数据
//热门职位
$.ajax({
    type: "get",
    url: "hotJobDetailList",
    success: function (result){
        console.log("结果集：" + result.data);
        var data = result.data.hotJobList.data;
        console.log("r1:" + data);
        var hotJobList = data.list;
        console.log("热门职位：==" + hotJobList);
        console.log("======================");

        $(".sub_li_centent ul").html("");

        for (var i=0; i<hotJobList.length; i++){
            var jobId = hotJobList[i].jobDetail.jobId;
            var jobName = hotJobList[i].jobDetail.jobName;
            var jobExperience = hotJobList[i].jobDetail.jobExperience;
            var jobLocCity = hotJobList[i].jobDetail.jobLocCity;
            var jobDegree = hotJobList[i].jobDetail.jobDegree;
            var companyName = hotJobList[i].companyDetail.companyName;
            var companyImg = hotJobList[i].companyDetail.companyImg
            var companyIndustry = hotJobList[i].companyDetail.companyIndustry
            var companyFinance = hotJobList[i].companyDetail.companyFinance
            var jobMinSalary=hotJobList[i].jobDetail.jobMinSalary;
            var jobMaxSalary=hotJobList[i].jobDetail.jobMaxSalary;
            var url="job/getById/"+jobId;

            var minS = '';
            var minSalary = String(jobMinSalary);
            if(minSalary.length == 4){
                minS = minSalary.substring(0,1);
            }else if (minSalary.length > 5 || minSalary.length == 5){
                minS = minSalary.substring(0,2);
            }



            var maxS = '';
            var maxSalary = String(jobMaxSalary);
            if (maxSalary.length == 4){
                maxS = maxSalary.substring(0,1);
            }else if (maxSalary.length > 5 || maxSalary.length == 5){
                maxS = maxSalary.substring(0,2);
            }


            var  jobEle = '<li>'+
                '<span class="name_desc">' +
                '<a href='+url+'>'+jobName+ '</a>'+
                ' </span>' +
                '<span class="name_salary">' +
                '<a href='+"javascript:void(0)"+'>'+minS+"-"+maxS+"K"+'</a>'+
                '</span>' +
                '<div class="work_demo">' +
                '<span class="work_space">'+jobLocCity+' </span>' +
                '<span class="work_years">'+jobExperience+'</span>' +
                '<span class="work_grand">'+jobDegree+'</span>' +
                '</div>' +
                '<div class="work_logo">' +
                '<img src="'+companyImg+'">'+
                '</div>' +
                '<div class="work_name">' +
                '<span>'+companyName+'</span>' +
                '</div>' +
                '<div class="work_information">' +
                '<span>'+companyIndustry+'</span>' +
                '<span class="work_information_e">'+companyFinance+'</span> ' +
                '</div>' +
                '</li>';

            $(".sub_li_centent ul").append(jobEle);
        }

    }
})


//热门企业
$.ajax({
    type: "get",
    url: "hostCompanyList",
    success: function (result){
        console.log("结果集：" + result.data);
        var data = result.data;
        console.log("r1:" + data);
        var hostCompanyList = data.hostCompanyList;
        var data1 = hostCompanyList.data;
        var companylist = data1.list;

        $(".company_tab_job ul").html("");
        for (var i=0; i < companylist.length; i++) {
            var companyId = companylist[i].companyDetail.companyId;
            var companyName = companylist[i].companyDetail.companyName;
            var companyImg = companylist[i].companyDetail.companyImg;
            var companyIndustry = companylist[i].companyDetail.companyIndustry;
            var companyScale = companylist[i].companyDetail.companyScale;
            var companyFinance = companylist[i].companyDetail.companyFinance;
            var jobDetailList = companylist[i].jobDetailList;
            var jobMinSalary1 = jobDetailList[0].jobMinSalary;
            var jobMaxSalary1 = jobDetailList[0].jobMaxSalary;
            var jobMinSalary2 = jobDetailList[1].jobMinSalary;
            var jobMaxSalary2 = jobDetailList[1].jobMaxSalary;
            var jobMinSalary3 = jobDetailList[2].jobMinSalary;
            var jobMaxSalary3 = jobDetailList[2].jobMaxSalary;

            var url1 = "job/getById/" + jobDetailList[0].jobId;
            var url2 = "job/getById/" + jobDetailList[1].jobId;
            var url3 = "job/getById/" + jobDetailList[2].jobId;
            var url4 = "companyDetail/toCompanyDetail?companyId="+ companyId;
            var url5 = "../link/public/Job/SearchJob.jsp";

            /*===============限制金额显示(拼接判断)==============================================*/
            var minS1 = '';
            var minSalary1 = String(jobMinSalary1);
            if(minSalary1.length == 4){
                minS1 = minSalary1.substring(0,1);
            }else if (minSalary1.length > 5 || minSalary1.length == 5){
                minS1 = minSalary1.substring(0,2);
            }
            var maxS1 = '';
            var maxSalary1 = String(jobMaxSalary1);
            if (maxSalary1.length == 4){
                maxS1 = maxSalary1.substring(0,1);
            }else if (maxSalary1.length > 5 || maxSalary1.length == 5){
                maxS1 = maxSalary1.substring(0,2);
            }
            var minS2= '';
            var minSalary2 = String(jobMinSalary2);
            if(minSalary2.length == 4){
                minS2 = minSalary2.substring(0,1);
            }else if (minSalary2.length > 5 || minSalary2.length == 5){
                minS2 = minSalary2.substring(0,2);
            }
            var maxS2 = '';
            var maxSalary2 = String(jobMaxSalary2);
            if (maxSalary2.length == 4){
                maxS2 = maxSalary2.substring(0,1);
            }else if (maxSalary2.length > 5 || maxSalary2.length == 5){
                maxS2 = maxSalary2.substring(0,2);
            }
            var minS3 = '';
            var minSalary3 = String(jobMinSalary3);
            if(minSalary3.length == 4){
                minS3 = minSalary3.substring(0,1);
            }else if (minSalary3.length > 5 || minSalary3.length == 5){
                minS3 = minSalary3.substring(0,2);
            }
            var maxS3 = '';
            var maxSalary3 = String(jobMaxSalary3);
            if (maxSalary3.length == 4){
                maxS3 = maxSalary3.substring(0,1);
            }else if (maxSalary3.length > 5 || maxSalary3.length == 5){
                maxS3 = maxSalary3.substring(0,2);
            }
            /*===============0=================================================*/

            /*
             ***渲染数据前的,数据获取测试(控制台)
             ***
            */
            /*
            console.log("1:" + companyId);
            console.log("2:" + companyName);
            console.log("3:" + companyImg);
            console.log("4:" + companyIndustry);
            console.log("5:" + companyScale);
            console.log("6:" + companyFinance);
            console.log("热数据:" + companylist.length);

            console.log("J@0:"+ JSON.stringify(jobDetailList[0]));
            console.log("J@1:"+ JSON.stringify(jobDetailList[1]));
            console.log("J@2:"+ JSON.stringify(jobDetailList[2]));*/

            var  companyEle = '<li>' +
                '<a href='+url4+' class="company_info_top">'+
                '<div class="company_img">'+
                '<img src="'+companyImg+'">'+
                '</div>'+
                '<div class="company_inform">'+
                '<h3>'+companyName+'</h3>'+
                '<p>'+ companyFinance +
                '<span class="vline">'+'</span>'+
                companyScale+
                '<span class="vline">'+'</span>'+
                companyIndustry+
                '</p>'+
                '</div>'+
                '</a>'+
                '<ul class="company_job_list">'+


                '<li class="company_job_item">'+
                '<a class="job_info" href='+url1+'>'+
                '<div class="job_info_top">'+
                '<p class="job_name">'+jobDetailList[0].jobName+'</p>'+
                '<i class="chat">'+'</i>'+
                '<p class="job_salary">'+minS1+"-"+maxS1+"k"+'</p>'+
                '</div>'+
                '<p class="job_text">'+
                '<span>'+jobDetailList[0].jobLocCity+" "+jobDetailList[0].jobLocArea+'</span>'+
                '<span>'+jobDetailList[0].jobExperience+'</span>'+
                '<span>'+jobDetailList[0].jobDegree+'</span>'+
                '</p>'+
                '</a>'+
                '</li>'+

                '<li class="company_job_item">'+
                '<a class="job_info" href='+url2+'>'+
                '<div class="job_info_top">'+
                '<p class="job_name">'+jobDetailList[1].jobName+'</p>'+
                '<i class="chat">'+'</i>'+
                '<p class="job_salary">'+minS2+"-"+maxS2+"k"+'</p>'+
                '</div>'+
                '<p class="job_text">'+
                '<span>'+jobDetailList[1].jobLocCity+" "+jobDetailList[1].jobLocArea+'</span>'+
                '<span>'+jobDetailList[1].jobExperience+'</span>'+
                '<span>'+jobDetailList[1].jobDegree+'</span>'+
                '</p>'+
                '</a>'+
                '</li>'+
                '<li class="company_job_item">'+
                '<a class="job_info" href='+url3+'>'+
                '<div class="job_info_top">'+
                '<p class="job_name">'+jobDetailList[2].jobName+'</p>'+
                '<i class="chat">'+'</i>'+
                '<p class="job_salary">'+minS2+"-"+maxS2+"k"+'</p>'+
                '</div>'+
                '<p class="job_text">'+
                '<span>'+jobDetailList[2].jobLocCity+" "+jobDetailList[2].jobLocArea+'</span>'+
                '<span>'+jobDetailList[2].jobExperience+'</span>'+
                '<span>'+jobDetailList[2].jobDegree+'</span>'+
                '</p>'+
                '</a>'+
                '</li>'+
                '</ul>'+
                '<a href='+url5+' class="more_job_btn">'+"产看更多职位"+'</a>'+
                '</li>';

            $(".company_tab_job ul").append(companyEle);
        }
    }
})
















/*
//关闭浏览器清除token
/!**
 * 在浏览器触发onunload事件的时候使用localStorage保存一个当前时间，在浏览器触发onload读取保存的时间，再创建一个新的时间，如果时间间隔大于3s，则清除token。这种和第二种的不同之处是这种大幅度延长了检测的interval，并且把这个清除token的操作从页面卸载转移到了页面装载。
 *
 * 作者：取名字真难啊
 * 链接：https://juejin.cn/post/6965747658094805006
 * 来源：稀土掘金
 * 著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。
 *!/
window.onload = function () {
    let lastTime = localStorage.getItem("lastTime");
    const interval = 3 * 1000;
    // 如果没有上一次离开的时间或者时间间隔大于3s，就清除token
    if (!lastTime || new Date().getTime() - lastTime > interval) {
        localStorage.removeItem("token");
        console.log("清除token")
    }else{
        console.log("时间过短不清除token")
    }
};
window.onunload = function () {
    sessionStorage.setItem("lastTime", new Date().getTime());
};*/


//用户退出登陆
/*
$(".logout").click(function (){
    var token = sessionStorage.getItem("token");
    if (token != null) {
        sessionStorage.removeItem("token");
        $(".login_info").css("display", "block");
        $(".login_info1").css("display", "none");
    }
})

*/






